package com.demo02_interaction.client;

import com.demo02_interaction.bean.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserServiceClientFallbackFactory implements FallbackFactory<UserServiceClient> {

    @Override
    public UserServiceClient create(Throwable cause) {
        return new UserServiceClient() {
            @Override
            public UserDTO getUserById(Long userId) {
                log.error("获取用户信息失败，用户ID: {}", userId, cause);
                throw new RuntimeException("无法获取用户信息，请稍后重试");
            }

            @Override
            public Boolean checkUserExists(Long userId) {
                log.error("检查用户存在失败，用户ID: {}", userId, cause);
                return false;
            }
        };
    }
}
